package com.spark.lola.statistics.entity;

import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.spark.lola.support.common.util.TimeUtil;
import com.spark.lola.support.mybatis.entity.BaseModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author: Zhi-peng wang
 * @date: 2020/05/14 11:18
 * 货运总量统计信息
 **/
@Getter
@Setter
@ApiModel(value = "StatisticsLogistics", description = "货运总量统计信息")
@TableName("statistics_logistics")
public class StatisticsLogistics extends BaseModel {

    @ApiModelProperty(name = "logisticsNumber", value = "货运数量")
    @ExcelProperty("货运数量")
    private Integer logisticsNumber;

    @ApiModelProperty(name = "logisticsMoney", value = "货运总金额")
    @ExcelProperty("货运总金额")
    private BigDecimal logisticsMoney;

    @ApiModelProperty(name = "logisticsSettlementMoney", value = "已结算货运金额")
    @ExcelProperty("已结算货运金额")
    private BigDecimal logisticsSettlementMoney;

    @ApiModelProperty(name = "logisticsNotSettlementMoney", value = "未结算货运金额")
    @ExcelProperty("未结算货运金额")
    private BigDecimal logisticsNotSettlementMoney;

    @ApiModelProperty(name = "logisticsExpensesMoney", value = "货运支出总金额")
    @ExcelProperty("货运支出总金额")
    private BigDecimal expensesMoney;

    @ApiModelProperty(name = "logisticsExpensesSettlementMoney", value = "已结算货运支出金额")
    @ExcelProperty("已结算货运支出金额")
    private BigDecimal expensesSettlementMoney;

    @ApiModelProperty(name = "logisticsExpensesNotSettlementMoney", value = "未结算货运支出金额")
    @ExcelProperty("未结算货运支出金额")
    private BigDecimal expensesNotSettlementMoney;

    @ApiModelProperty(name = "logisticsTotalWeight", value = "货运总重（t）")
    @ExcelProperty("货运总重（t）")
    private BigDecimal logisticsTotalWeight;

    @ApiModelProperty(name = "logisticsMileage", value = "货运里程")
    @ExcelProperty("货运里程")
    private Integer logisticsMileage;

    @ApiModelProperty(name = "createDate", value = "创建日期 yyyy-MM-dd")
    @ExcelProperty("创建日期 yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date createDate;

    @ApiModelProperty(name = "createMonth", value = "创建月份 yyyyMM")
    @ExcelProperty("创建月份 yyyyMM")
    private Integer createMonth;

    @ApiModelProperty(name = "createYear", value = "创建年份yyyy")
    @ExcelProperty("创建年份yyyy")
    private Integer createYear;

    @ApiModelProperty(name = "updateTime", value = "修改时间")
    @ExcelProperty("修改时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    public StatisticsLogistics() {
        this.logisticsNumber = 0;
        this.logisticsMoney = BigDecimal.ZERO;
        this.logisticsSettlementMoney = BigDecimal.ZERO;
        this.logisticsNotSettlementMoney = BigDecimal.ZERO;
        this.expensesMoney = BigDecimal.ZERO;
        this.expensesSettlementMoney = BigDecimal.ZERO;
        this.expensesNotSettlementMoney = BigDecimal.ZERO;
        this.logisticsTotalWeight = BigDecimal.ZERO;
        this.logisticsMileage = 0;
    }

    public StatisticsLogistics(Date date) {
        this.logisticsNumber = 0;
        this.logisticsMoney = BigDecimal.ZERO;
        this.logisticsSettlementMoney = BigDecimal.ZERO;
        this.logisticsNotSettlementMoney = BigDecimal.ZERO;
        this.expensesMoney = BigDecimal.ZERO;
        this.expensesSettlementMoney = BigDecimal.ZERO;
        this.expensesNotSettlementMoney = BigDecimal.ZERO;
        this.logisticsTotalWeight = BigDecimal.ZERO;
        this.logisticsMileage = 0;
        this.createDate = date;
        this.createMonth = TimeUtil.getMonth(date);
        this.createYear = TimeUtil.getYear(date);
    }

    public StatisticsLogistics(Date date, BigDecimal actualAmount, BigDecimal transportTotal) {
        this.logisticsNumber = 1;
        this.logisticsMoney = actualAmount;
        this.logisticsSettlementMoney = BigDecimal.ZERO;
        this.logisticsNotSettlementMoney = actualAmount;
        this.expensesMoney = BigDecimal.ZERO;
        this.expensesSettlementMoney = BigDecimal.ZERO;
        this.expensesNotSettlementMoney = BigDecimal.ZERO;
        this.logisticsTotalWeight = transportTotal;
        this.logisticsMileage = 0;
        this.createDate = date;
        this.createMonth = TimeUtil.getMonth(date);
        this.createYear = TimeUtil.getYear(date);
    }

    public StatisticsLogistics(Date date, int logisticsMileage, BigDecimal refundableFee) {
        this.logisticsNumber = 0;
        this.logisticsMoney = BigDecimal.ZERO;
        this.logisticsSettlementMoney = BigDecimal.ZERO;
        this.logisticsNotSettlementMoney = BigDecimal.ZERO;
        this.expensesMoney = refundableFee;
        this.expensesSettlementMoney = BigDecimal.ZERO;
        this.expensesNotSettlementMoney = refundableFee;
        this.logisticsTotalWeight = BigDecimal.ZERO;
        this.logisticsMileage = logisticsMileage;
        this.createDate = date;
        this.createMonth = TimeUtil.getMonth(date);
        this.createYear = TimeUtil.getYear(date);
    }

    public StatisticsLogistics(StatisticsLogistics statisticsLogistics, int logisticsNumber, BigDecimal actualAmount, BigDecimal transportTotal, BigDecimal settlementMoney) {
        this.id = statisticsLogistics.getId();
        this.logisticsNumber = statisticsLogistics.getLogisticsNumber() + logisticsNumber;
        this.logisticsMoney = statisticsLogistics.getLogisticsMoney().add(actualAmount);
        this.logisticsSettlementMoney = statisticsLogistics.getLogisticsSettlementMoney().add(settlementMoney);
        this.logisticsNotSettlementMoney = statisticsLogistics.getLogisticsNotSettlementMoney().add(actualAmount);
        this.logisticsTotalWeight = statisticsLogistics.getLogisticsTotalWeight().add(transportTotal);
        this.setVersion(statisticsLogistics.getVersion());
    }

    public StatisticsLogistics(StatisticsLogistics statisticsLogistics, int logisticsMileage, BigDecimal refundableFee, BigDecimal settlementMoney) {
        this.id = statisticsLogistics.getId();
        this.expensesMoney = statisticsLogistics.getExpensesMoney().add(refundableFee);
        this.expensesSettlementMoney = statisticsLogistics.getExpensesSettlementMoney().add(settlementMoney);
        this.expensesNotSettlementMoney = statisticsLogistics.getExpensesNotSettlementMoney().add(refundableFee);
        this.logisticsMileage = statisticsLogistics.getLogisticsMileage() + logisticsMileage;
        this.setVersion(statisticsLogistics.getVersion());
    }

}
